package com.ruoyi.web.controller.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import com.kingdee.bos.webapi.entity.RepoRet;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import com.ruoyi.system.domain.UserModel;
import com.ruoyi.web.core.config.SeqHelper;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import java.util.*;
import java.util.stream.Collectors;

import static org.junit.Assert.fail;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class PurPurchaseOrderPushTest {
    K3CloudApi api = new K3CloudApi();
    static String FNumber = SeqHelper.genNumber("CGDD");
    static String FName = "aucgdd_" + UUID.randomUUID().toString();
    private static String chaseorderid = "";
    private static String POChangeid = "";


    String json = "{ \"NeedUpDateFields\": [], \"NeedReturnFields\": [], \"IsDeleteEntry\": \"true\", \"SubSystemId\": \"\", \"IsVerifyBaseDataField\": \"false\", \"IsEntryBatchFill\": \"true\", \"ValidateFlag\": \"true\", \"NumberSearch\": \"true\", \"IsAutoAdjustField\": \"false\", \"InterationFlags\": \"\", \"IgnoreInterationFlag\": \"\", \"IsControlPrecision\": \"false\", \"ValidateRepeatJson\": \"false\", \"Model\": { \"FBillTypeID\": { \"FNUMBER\": \"CGDD01_SYS\" }, \"FDate\": \"2022-09-29 00:00:00\", \"FSupplierId\": { \"FNumber\": \"FINGYS000100\" }, \"FPurchaseOrgId\": { \"FNumber\": \"100\" }, \"FProviderId\": { \"FNumber\": \"FINGYS000100\" }, \"FSettleId\": { \"FNumber\": \"FINGYS000100\" }, \"FChargeId\": { \"FNumber\": \"FINGYS000100\" }, \"FChangeStatus\": \"A\", \"FACCTYPE\": \"Q\", \"FPOOrderFinance\": { \"FSettleCurrId\": { \"FNumber\": \"PRE001\" }, \"FExchangeTypeId\": { \"FNumber\": \"HLTX01_SYS\" }, \"FExchangeRate\": 1, \"FPriceTimePoint\": \"1\", \"FFOCUSSETTLEORGID\": { \"FNumber\": \"100\" }, \"FIsIncludedTax\": true, \"FISPRICEEXCLUDETAX\": true, \"FLocalCurrId\": { \"FNumber\": \"PRE001\" }, \"FSupToOderExchangeBusRate\": 1 }, \"FPOOrderEntry\": [ { \"FProductType\": \"1\", \"FMaterialId\": { \"FNumber\": \"BOSTEST001\" }, \"FMaterialDesc\": \"BOSTEST001\", \"FUnitId\": { \"FNumber\": \"Pcs\" }, \"FQty\": 1, \"FPriceUnitId\": { \"FNumber\": \"Pcs\" }, \"FPriceUnitQty\": 1, \"FPriceBaseQty\": 1, \"FDeliveryDate\": \"2022-09-29 10:42:29\", \"FEntryTaxRate\": 13, \"FRequireOrgId\": { \"FNumber\": \"100\" }, \"FReceiveOrgId\": { \"FNumber\": \"100\" }, \"FEntrySettleOrgId\": { \"FNumber\": \"100\" }, \"FStockUnitID\": { \"FNumber\": \"Pcs\" }, \"FStockQty\": 1, \"FStockBaseQty\": 1, \"FDeliveryMaxQty\": 1, \"FDeliveryMinQty\": 1, \"FDeliveryEarlyDate\": \"2022-09-29 10:42:29\", \"FDeliveryLastDate\": \"2022-09-29 10:42:29\", \"FPriceCoefficient\": 1, \"FPlanConfirm\": true, \"FSalUnitID\": { \"FNumber\": \"Pcs\" }, \"FSalQty\": 1, \"FCentSettleOrgId\": { \"FNumber\": \"100\" }, \"FDispSettleOrgId\": { \"FNumber\": \"100\" }, \"FDeliveryStockStatus\": { \"FNumber\": \"KCZT02_SYS\" }, \"FSalBaseQty\": 1, \"FEntryPayOrgId\": { \"FNumber\": \"100\" }, \"FEntryDeliveryPlan\": [ { \"FDeliveryDate_Plan\": \"2022-09-29 10:42:29\", \"FPlanQty\": 1, \"FPREARRIVALDATE\": \"2022-09-29 10:42:29\" } ] } ], \"FBillNo\":"+"\""+FNumber+"\""+" }}";
    @Test
    public void selectPer(){

        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\n" +
                "  \"NeedUpDateFields\": [],\n" +
                "  \"NeedReturnFields\": [],\n" +
                "  \"IsDeleteEntry\": \"true\",\n" +
                "  \"SubSystemId\": \"\",\n" +
                "  \"IsVerifyBaseDataField\": \"false\",\n" +
                "  \"IsEntryBatchFill\": \"true\",\n" +
                "  \"ValidateFlag\": \"true\",\n" +
                "  \"NumberSearch\": \"true\",\n" +
                "  \"IsAutoAdjustField\": \"false\",\n" +
                "  \"InterationFlags\": \"\",\n" +
                "  \"IgnoreInterationFlag\": \"\",\n" +
                "  \"IsControlPrecision\": \"false\",\n" +
                "  \"ValidateRepeatJson\": \"false\",\n" +
                "  \"Model\": {\n" +
                "    \"FID\": 0,\n" +
                "    \"FBillTypeID\": {\n" +
                "      \"FNUMBER\": \"CGSQD01_SYS\"\n" +
                "    },\n" +
                "    \"FBillNo\": \"\",\n" +
                "    \"FApplicationDate\": \"1900-01-01\",\n" +
                "    \"FRequestType\": \"\",\n" +
                "    \"FApplicationOrgId\": {\n" +
                "      \"FNumber\": \"101\"\n" +
                "    },\n" +
                "    \"FApplicationDeptId\": {\n" +
                "      \"FNumber\": \"\"\n" +
                "    },\n" +
                "    \"FApplicantId\": {},\n" +
                "    \"FCurrencyId\": {\n" +
                "      \"FNumber\": \"\"\n" +
                "    },\n" +
                "    \"FNote\": \"\",\n" +
                "    \"FSrcType\": \"\",\n" +
                "    \"FISPRICEEXCLUDETAX\": \"false\",\n" +
                "    \"FExchangeTypeId\": {\n" +
                "      \"FNumber\": \"\"\n" +
                "    },\n" +
                "    \"FIsConvert\": \"false\",\n" +
                "    \"FACCTYPE\": \"\",\n" +
                "    \"FCloseReason\": \"\",\n" +
                "    \"FIsCreateStraightOutIN\": \"false\",\n" +
                "    \"FMobBillHead\": {\n" +
                "      \"FEntryId\": 0,\n" +
                "      \"FExtendField\": \"\",\n" +
                "      \"FOrderName\": \"\",\n" +
                "      \"FIsMobBill\": \"false\",\n" +
                "      \"FMobIsPending\": \"false\"\n" +
                "    },\n" +
                "    \"FEntity\": [\n" +
                "      {\n" +
                "        \"FEntryID\": 0,\n" +
                "        \"FRequireOrgId\": {\n" +
                "          \"FNumber\": \"101\"\n" +
                "        },\n" +
                "        \"FMaterialId\": {\n" +
                "          \"FNumber\": \"2022073021-QC01\"\n" +
                "        },\n" +
                "        \"FMaterialDesc\": \"\",\n" +
                "        \"FAuxpropId\": {},\n" +
                "        \"FUnitId\": {\n" +
                "          \"FNumber\": \"tao\"\n" +
                "        },\n" +
                "        \"FReqQty\": 2,\n" +
                "        \"FApproveQty\": 0,\n" +
                "        \"FPurchaseOrgId\": {\n" +
                "          \"FNumber\": \"101\"\n" +
                "        },\n" +
                "        \"FSuggestSupplierId\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FReceiveOrgId\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FEvaluatePrice\": 0,\n" +
                "        \"FTAXPRICE\": 0,\n" +
                "        \"FTAXRATE\": 0,\n" +
                "        \"FPriceUnitId\": {\n" +
                "          \"FNumber\": \"tao\"\n" +
                "        },\n" +
                "        \"FPriceUnitQty\": 0,\n" +
                "        \"FREQSTOCKUNITID\": {\n" +
                "          \"FNumber\": \"tao\"\n" +
                "        },\n" +
                "        \"FREQSTOCKQTY\": 0,\n" +
                "        \"FLeadTime\": 0,\n" +
                "        \"FSrcBillTypeId\": \"\",\n" +
                "        \"FSupplierId\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FSrcBillNo\": \"\",\n" +
                "        \"FChargeProjectID\": {\n" +
                "          \"FNUMBER\": \"\"\n" +
                "        },\n" +
                "        \"FPurchaseDeptId\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FReceiveAddress\": \"\",\n" +
                "        \"FEntryNote\": \"\",\n" +
                "        \"FPurchaserId\": {\n" +
                "          \"FNUMBER\": \"\"\n" +
                "        },\n" +
                "        \"FPurchaseGroupId\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FBOMNoId\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FStockId\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FProviderId\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FMtoNo\": \"\",\n" +
                "        \"FBaseReqQty\": 0,\n" +
                "        \"FReceiveDeptId\": {\n" +
                "          \"FNUMBER\": \"\"\n" +
                "        },\n" +
                "        \"FRequireDeptId\": {\n" +
                "          \"FNUMBER\": \"\"\n" +
                "        },\n" +
                "        \"FSalUnitID\": {\n" +
                "          \"FNumber\": \"\"\n" +
                "        },\n" +
                "        \"FSalQty\": 0,\n" +
                "        \"FSalBaseQty\": 0,\n" +
                "        \"FIsVmiBusiness\": \"false\",\n" +
                "        \"FDEMANDTYPE\": \"\",\n" +
                "        \"FDEMANDBILLNO\": \"\",\n" +
                "        \"FDEMANDBILLENTRYSEQ\": 0,\n" +
                "        \"FDEMANDBILLENTRYID\": 0,\n" +
                "        \"FSrcReqMergeEntryIds\": \"\",\n" +
                "        \"FAssortBillNo\": \"\",\n" +
                "        \"FSupMatId\": \"\",\n" +
                "        \"FSupMatName\": \"\"\n" +
                "      }\n" +
                "    ]\n" +
                "  }\n" +
                "}";
        try{
            //业务对象标识
            String formId = "PUR_Requisition";
            //调用接口
            String resultJson = client.save(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                System.out.println("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            System.out.println("接口返回结果: " + e.getMessage());
        }
    }
    @Test
    public void scc(){
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\"CreateOrgId\":0,\"Number\":\"CGSQ000350\",\"Id\":\"100361\",\"IsSortBySeq\":\"false\"}";
        try{
            //业务对象标识
            String formId = "PUR_Requisition";
            //调用接口
            String resultJson = client.view(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }

    }

    @Test
    public void savePerson(){
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
//        String jsonData = "{\"Model\":{\"FName\":\"test123456789\"}}";
//        String jsonData = "{\"Model\":{\"FID\":141238,\"FUseOrgId\":{\"FNumber\":\"101\"},\"fPostEntity\":{\"FPostDept\":{\"FNumber\":\"BM000044\"}},\"FStaffNumber\":\"0763\",\"FName\":\"张乐华\"}}";
        String jsonData = " {\"Model\":{\"FID\":107150,\"FUseOrgId\":{\"FNumber\":\"101\"},\"fPostEntity\":[ {\n" +
                "                \"FWorkOrgId\": {\n" +
                "                    \"FNumber\": \"101\"\n" +
                "                },\n" +
                "                \"FPostDept\": {\n" +
                "                    \"FNumber\": \"BM000017\"\n" +
                "                },\n" +
//                "                \"FPost\": {\n" +
//                "                    \"FNumber\": \"GW000017\"\n" +
//                "                },\n" +
                "            }],\"FStaffNumber\":\"00024\",\"FName\":\"陈洁\"}}";
        try{
            //业务对象标识
            String formId = "BD_Empinfo";
            //调用接口
            String resultJson = client.save(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
                String number = repoRet.getResult().getResponseStatus().getSuccessEntitys().get(0).getNumber();
                System.out.println("人员编号："+number);
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
    @Test
    public void savefPerson(){
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\"CreateOrgId\":0,\"Numbers\":[],\"Ids\":\"139463\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"UseOrgId\":0,\"NetworkCtrl\":\"\",\"IsVerifyProcInst\":\"true\"}";
        try{
            //业务对象标识
            String formId = "BD_Empinfo";
            //调用接口
            String resultJson = client.unAudit(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
    @Test
    public void delPerson() {
        K3CloudApi client = new K3CloudApi();
//请求参数，要求为json字符串
        String jsonData = "{\"Numbers\":[\"0024\"]}";
        try{
            //业务对象标识
            String formId = "BD_Empinfo";
            //操作接口编码
            String operateNumber = "Forbid";
            //调用接口
            String resultJson = client.excuteOperation(formId,operateNumber,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                System.out.printf("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            System.out.printf(e.getMessage());
        }
    }

    @Test
    public void updatePerson(){
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"IsControlPrecision\":\"false\",\"ValidateRepeatJson\":\"false\",\"Model\":{\"FID\":0,\"FName\":\"test1233\",\"FStaffNumber\":\"\",\"FMobile\":\"\",\"FTel\":\"\",\"FEmail\":\"\",\"FDescription\":\"\",\"FAddress\":\"\",\"FUseOrgId\":{\"FNumber\":\"101\"},\"FCreateOrgId\":{\"FNumber\":\"101\"},\"FBranchID\":{\"FNUMBER\":\"\"},\"FCreateSaler\":\"false\",\"FCreateUser\":\"false\",\"FUserRole\":[{\"FNumber\":\"\"}],\"FCreateCashier\":\"false\",\"FCashierGrp\":{\"FNUMBER\":\"\"},\"FSalerId\":{\"FNUMBER\":\"\"},\"FCashierId\":{\"FNUMBER\":\"\"},\"FUserId\":{\"FUSERACCOUNT\":\"\"},\"FPostId\":{\"FNUMBER\":\"\"},\"FJoinDate\":\"1900-01-01\",\"FUniportalNo\":\"\",\"FSHRMapEntity\":{\"FMAPID\":0},\"FBankInfo\":[{\"FBankId\":0,\"FBankCountry\":{\"FNumber\":\"\"},\"FBankCode\":\"\",\"FBankTypeRec\":{\"FNUMBER\":\"\"},\"FBankHolder\":\"\",\"FTextBankDetail\":\"\",\"FBankDetail\":{\"FNUMBER\":\"\"},\"FOpenBankName\":\"\",\"FOpenAddressRec\":\"\",\"FCNAPS\":\"\",\"FBankCurrencyId\":{\"FNUMBER\":\"\"},\"FBankIsDefault\":\"false\",\"FBankDesc\":\"\",\"FIsFromSHR\":\"false\",\"FCertType\":\"\",\"FCertNum\":\"\"}]}}";
        try{
            //业务对象标识
            String formId = "BD_Empinfo";
            //调用接口
            String resultJson = client.submit(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
    @Test
    public void getJDPerson() {
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\n" +
                "    \"FormId\": \"BD_Empinfo\",\n" +
                "    \"FieldKeys\": \"FName,Fnumber,FBaseProperty3,FID,FUseOrgId.FNumber,FPostDept.FNumber,FMobile,FForbidStatus,FDocumentStatus,FCreateOrgId\",\n" +
//                "    \"FilterString\": [{\"FieldName\":\"FForbidStatus\",\"Compare\":\"67\",\"Value\":\"A\",\"Left\":\"\",\"Right\":\"\",\"Logic\":\"0\"}],\n" +
                "    \"FilterString\": \"FForbidStatus='A'\",\n" +
                "    \"OrderString\": \"\",\n" +
                "    \"TopRowCount\": 0,\n" +
                "    \"StartRow\": 0,\n" +
                "    \"Limit\": 0,\n" +
                "    \"SubSystemId\": \"\"\n" +
                "}";
        String resultJson = null;
        List<UserModel> resultList = new ArrayList<>();
        try {
            //调用接口
            List<List<Object>> lists = client.executeBillQuery(jsonData);

            System.out.println("接口返回结果: " + String.valueOf(lists));
            for (List<Object> list : lists) {
                UserModel userModel = new UserModel();
                userModel.setFName((String) list.get(0));
                userModel.setFNumber((String) list.get(1));
                userModel.setFBaseProperty3((String) list.get(2));
                userModel.setFdId((Integer) list.get(3));
                userModel.setShiyongzuzhi((String) list.get(4));
                userModel.setFdDeptNo((String) list.get(5));
                resultList.add(userModel);
            }

            Map<String, Object> map = new HashMap<>();
            for (UserModel userModel : resultList) {
                if (!map.containsKey(userModel.getFNumber())) {
                    map.put(userModel.getFNumber(), userModel);
                } else {
                    UserModel userModel1 = (UserModel) map.get(userModel.getFNumber());
                    userModel1.setCount(2);
                    map.remove(userModel.getFNumber());
                    map.put(userModel1.getFNumber(), userModel1);
                }
            }
            System.out.println("===="+map);
        } catch (Exception e) {
            System.out.println("接口错误信息：" + e.getMessage());
        }
    }

    //接口返回结果: {"Id":"100361","ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":"100361","Number":"CGSQ000350","DIndex":0}]}}
//    {"Id":"100362","ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":"100362","Number":"CGSQ000351","DIndex":0}]}}
    //{"Id":"100363","ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":"100363","Number":"CGSQ000352","DIndex":0}]}}
    @Test
    public void dd(){

        //注意 1：此处不再使用参数形式传入用户名及密码等敏感信息，改为在登录配置文件中设置。
        //注意 2：必须先配置第三方系统登录授权信息后，再进行业务操作，详情参考各语言版本SDK介绍中的登录配置文件说明。
        //读取配置，初始化SDK
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\"CreateOrgId\":0,\"Numbers\":[],\"Ids\":\"100363\",\"SelectedPostId\":0,\"UseOrgId\":0,\"NetworkCtrl\":\"\",\"IgnoreInterationFlag\":\"\"}";
        try{
            //业务对象标识
            String formId = "PUR_Requisition";
            //调用接口
            String resultJson = client.submit(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    @Test
    public void cc(){

        //注意 1：此处不再使用参数形式传入用户名及密码等敏感信息，改为在登录配置文件中设置。
        //注意 2：必须先配置第三方系统登录授权信息后，再进行业务操作，详情参考各语言版本SDK介绍中的登录配置文件说明。
        //读取配置，初始化SDK
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\"CreateOrgId\":0,\"Numbers\":[],\"Ids\":\"100363\",\"InterationFlags\":\"\",\"UseOrgId\":0,\"NetworkCtrl\":\"\",\"IsVerifyProcInst\":\"true\",\"IgnoreInterationFlag\":\"\",\"UseBatControlTimes\":\"false\"}";
        try{
            //业务对象标识
            String formId = "PUR_Requisition";
            //调用接口
            String resultJson = client.audit(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    /***
     * 凭证保存
     * @throws Exception
     */
    @Test
    public void ddd() throws Exception{
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\n" +
                "    \"NeedUpDateFields\": [],\n" +
                "    \"NeedReturnFields\": [],\n" +
                "    \"IsDeleteEntry\": \"true\",\n" +
                "    \"SubSystemId\": \"\",\n" +
                "    \"IsVerifyBaseDataField\": \"false\",\n" +
                "    \"IsEntryBatchFill\": \"true\",\n" +
                "    \"ValidateFlag\": \"true\",\n" +
                "    \"NumberSearch\": \"true\",\n" +
                "    \"IsAutoAdjustField\": \"false\",\n" +
                "    \"InterationFlags\": \"\",\n" +
                "    \"IgnoreInterationFlag\": \"\",\n" +
                "    \"IsControlPrecision\": \"false\",\n" +
                "    \"ValidateRepeatJson\": \"false\",\n" +
                "    \"Model\": {\n" +
                "        \"FVOUCHERID\": 0,\n" +
                "        \"FAccountBookID\": {\n" +
                "            \"FNumber\": \"101\"\n" +
                "        },\n" +
                "        \"FDate\": \"2023-12-31 00:00:00\",\n" +
                "        \"FBUSDATE\": \"2023-12-31 00:00:00\",\n" +
                "        \"FYEAR\": 2023,\n" +
                "        \"FPERIOD\": 12,\n" +
                "        \"FVOUCHERGROUPID\": {\n" +
                "            \"FNumber\": \"PRE001\"\n" +
                "        },\n" +
                "        \"FVOUCHERGROUPNO\": \"24\",\n" +
                "        \"FATTACHMENTS\": 0,\n" +
                "        \"FISADJUSTVOUCHER\": false,\n" +
                "        \"FSourceBillKey\": {\n" +
                "            \"FNumber\": \"78050206-2fa6-40e3-b7c8-bd608146fa38\"\n" +
                "        },\n" +
                "        \"FDocumentStatus\": \"Z\",\n" +
                "        \"FEntity\": [\n" +
                "            {\n" +
                "                \"FEXPLANATION\": \"222\",\n" +
                "                \"FACCOUNTID\": {\n" +
                "                    \"FNumber\": \"1001.01\"\n" +
                "                },\n" +
                "                \"FCURRENCYID\": {\n" +
                "                    \"FNumber\": \"PRE001\"\n" +
                "                },\n" +
                "                \"FEXCHANGERATETYPE\": {\n" +
                "                    \"FNumber\": \"HLTX01_SYS\"\n" +
                "                },\n" +
                "                \"FEXCHANGERATE\": 1.0,\n" +
                "                \"FPrice\": 0.0,\n" +
                "                \"FQty\": 0.0,\n" +
                "                \"FAMOUNTFOR\": 222.0,\n" +
                "                \"FDEBIT\": 222.0,\n" +
                "                \"FCREDIT\": 0.0,\n" +
                "                \"FEXPORTENTRYID\": 0\n" +
                "            },\n" +
                "            {\n" +
                "                \"FEXPLANATION\": \"222\",\n" +
                "                \"FACCOUNTID\": {\n" +
                "                    \"FNumber\": \"1001.01\"\n" +
                "                },\n" +
                "                \"FCURRENCYID\": {\n" +
                "                    \"FNumber\": \"PRE001\"\n" +
                "                },\n" +
                "                \"FEXCHANGERATETYPE\": {\n" +
                "                    \"FNumber\": \"HLTX01_SYS\"\n" +
                "                },\n" +
                "                \"FEXCHANGERATE\": 1.0,\n" +
                "                \"FPrice\": 0.0,\n" +
                "                \"FQty\": 0.0,\n" +
                "                \"FAMOUNTFOR\": 222.0,\n" +
                "                \"FDEBIT\": 0.0,\n" +
                "                \"FCREDIT\": 222.0,\n" +
                "                \"FEXPORTENTRYID\": 0\n" +
                "            }\n" +
                "        ]\n" +
                "    }\n" +
                "}";
        try{
            //业务对象标识
            String formId = "GL_VOUCHER";
            //调用接口
            String resultJson = client.save(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    //{"Id":"100564","ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":"100564","Number":"551","DIndex":0}]}}
    /**
     * 凭证提交
     */
    @Test
    public void dddd(){
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\"CreateOrgId\":0,\"Numbers\":[],\"Ids\":\"100564\",\"SelectedPostId\":0,\"UseOrgId\":0,\"NetworkCtrl\":\"\",\"IgnoreInterationFlag\":\"\"}";
        try{
            //业务对象标识
            String formId = "GL_VOUCHER";
            //调用接口
            String resultJson = client.submit(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    /**
     * 付款单-费用报销单/采购业务付款单
     */
    @Test
    public void cdd(){
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\n" +
                "    \"Model\": {\n" +
                "        \"FBillTypeID\": {\n" +
                "            \"FNUMBER\": \"FKDLX04_SYS\"\n" +
                "        },\n" +
                "        \"FDATE\": \"2024-12-02 00:00:00\",\n" +
                "        \"FCONTACTUNITTYPE\": \"BD_Empinfo\",\n" +
                "        \"FCONTACTUNIT\": {\n" +
                "            \"FNumber\": \"00016\"\n" +
                "        },\n" +
                "        \"FRECTUNITTYPE\": \"BD_Empinfo\",\n" +
                "        \"FRECTUNIT\": {\n" +
                "            \"FNumber\": \"00016\"\n" +
                "        },\n" +
                "        \"FCURRENCYID\": {\n" +
                "            \"FNumber\": \"PRE001\"\n" +
                "        },\n" +
                "        \"FDOCUMENTSTATUS\": \"Z\",\n" +
                "        \"FBUSINESSTYPE\": \"3\",\n" +
                "        \"FCancelStatus\": \"A\",\n" +
                "        \"FPAYORGID\": {\n" +
                "            \"FNumber\": \"101\"\n" +
                "        },\n" +
                "        \"FSETTLEORGID\": {\n" +
                "            \"FNUMBER\": \"101\"\n" +
                "        },\n" +
                "        \"FDepartment\": {\n" +
                "            \"FNUMBER\": \"PRE001\"\n" +
                "        },\n" +
                "        \"FREMARK\": \"12\",\n" +
                "        \"FSETTLECUR\": {\n" +
                "            \"FNUMBER\": \"PRE001\"\n" +
                "        },\n" +
                "        \"FMatchMethodID\": 0,\n" +
                "        \"FISCARRYRATE\": false,\n" +
                "        \"FSETTLEMAINBOOKID\": {\n" +
                "            \"FNUMBER\": \"PRE001\"\n" +
                "        },\n" +
                "        \"FMoreReceive\": false,\n" +
                "        \"FVirIsSameAcctOrg\": false,\n" +
                "        \"FPAYBILLENTRY\": [\n" +
                "            {\n" +
                "                \"FSETTLETYPEID\": {\n" +
                "                    \"FNumber\": \"JSFS01_SYS\"\n" +
                "                },\n" +
                "                \"FPURPOSEID\": {\n" +
                "                    \"FNumber\": \"SFKYT10_SYS\"\n" +
                "                },\n" +
                "                \"FPAYTOTALAMOUNTFOR\": 5.0,\n" +
                "                \"FPAYAMOUNTFOR_E\": 5.0,\n" +
                "                \"FSETTLEDISTAMOUNTFOR\": 0.0,\n" +
                "                \"FSETTLEPAYAMOUNTFOR\": 5.0,\n" +
                "                \"FOVERSHORTAGEFOR\": 0.0,\n" +
                "                \"FHANDLINGCHARGEFOR\": 0.0,\n" +
                "                \"FPURCHASEORDERID\": 0,\n" +
                "                \"FRecType\": \"1\",\n" +
                "                \"FPOSTDATE\": \"2024-12-02 00:00:00\",\n" +
                "                \"FRuZhangType\": \"1\",\n" +
                "                \"FPayType\": \"A\",\n" +
                "                \"F_IsIinvoice\": false\n" +
                "            }\n" +
                "        ]\n" +
                "    }\n" +
                "}";
//        String jsonData = "{\n" +
//                "    \"NeedUpDateFields\": [],\n" +
//                "    \"NeedReturnFields\": [],\n" +
//                "    \"IsDeleteEntry\": \"true\",\n" +
//                "    \"SubSystemId\": \"\",\n" +
//                "    \"IsVerifyBaseDataField\": \"false\",\n" +
//                "    \"IsEntryBatchFill\": \"true\",\n" +
//                "    \"ValidateFlag\": \"true\",\n" +
//                "    \"NumberSearch\": \"true\",\n" +
//                "    \"IsAutoAdjustField\": \"false\",\n" +
//                "    \"InterationFlags\": \"\",\n" +
//                "    \"IgnoreInterationFlag\": \"\",\n" +
//                "    \"IsControlPrecision\": \"false\",\n" +
//                "    \"ValidateRepeatJson\": \"false\",\n" +
//                "    \"Model\": {\n" +
//                "        \"FID\": 0,\n" +
//                "        \"FBillTypeID\": {\n" +
//                "            \"FNUMBER\": \"FKDLX01_SYS\"\n" +
//                "        },\n" +
//                "        \"FDATE\": \"2024-12-02 00:00:00\",\n" +
//                "        \"FCONTACTUNITTYPE\": \"BD_Supplier\",\n" +
//                "        \"FCONTACTUNIT\": {\n" +
//                "            \"FNumber\": \"VEN00003\"\n" +
//                "        },\n" +
//                "        \"FRECTUNITTYPE\": \"BD_Supplier\",\n" +
//                "        \"FRECTUNIT\": {\n" +
//                "            \"FNumber\": \"VEN00003\"\n" +
//                "        },\n" +
//                "        \"FISINIT\": false,\n" +
//                "        \"FCURRENCYID\": {\n" +
//                "            \"FNumber\": \"PRE001\"\n" +
//                "        },\n" +
//                "        \"FEXCHANGERATE\": 1.0,\n" +
//                "        \"FSETTLERATE\": 1.0,\n" +
//                "        \"FSETTLEORGID\": {\n" +
//                "            \"FNumber\": \"101\"\n" +
//                "        },\n" +
//                "        \"FPURCHASEORGID\": {\n" +
//                "            \"FNumber\": \"101\"\n" +
//                "        },\n" +
//                "        \"FDOCUMENTSTATUS\": \"Z\",\n" +
//                "        \"FBUSINESSTYPE\": \"2\",\n" +
//                "        \"FCancelStatus\": \"A\",\n" +
//                "        \"FPAYORGID\": {\n" +
//                "            \"FNumber\": \"101\"\n" +
//                "        },\n" +
//                "        \"FISSAMEORG\": true,\n" +
//                "        \"FIsCredit\": false,\n" +
//                "        \"FSETTLECUR\": {\n" +
//                "            \"FNUMBER\": \"PRE001\"\n" +
//                "        },\n" +
//                "        \"FIsWriteOff\": false,\n" +
//                "        \"FMatchMethodID\": 0,\n" +
//                "        \"FREALPAY\": false,\n" +
//                "        \"FISCARRYRATE\": false,\n" +
//                "        \"FSETTLEMAINBOOKID\": {\n" +
//                "            \"FNUMBER\": \"PRE001\"\n" +
//                "        },\n" +
//                "        \"FMoreReceive\": false,\n" +
//                "        \"FVirIsSameAcctOrg\": false,\n" +
//                "        \"FPAYBILLENTRY\": [\n" +
//                "            {\n" +
//                "                \"FSETTLETYPEID\": {\n" +
//                "                    \"FNumber\": \"JSFS01_SYS\"\n" +
//                "                },\n" +
//                "                \"FPURPOSEID\": {\n" +
//                "                    \"FNumber\": \"SFKYT08_SYS\"\n" +
//                "                },\n" +
//                "                \"FPAYTOTALAMOUNTFOR\": 2.0,\n" +
//                "                \"FPAYAMOUNTFOR_E\": 2.0,\n" +
//                "                \"FSETTLEDISTAMOUNTFOR\": 0.0,\n" +
//                "                \"FSETTLEPAYAMOUNTFOR\": 2.0,\n" +
//                "                \"FOVERSHORTAGEFOR\": 0.0,\n" +
//                "                \"FHANDLINGCHARGEFOR\": 0.0,\n" +
//                "                \"FOPPOSITEBANKACCOUNT\": \"112233\",\n" +
//                "                \"FOPPOSITEBANKNAME\": \"北方银行\",\n" +
//                "                \"FPURCHASEORDERID\": 0,\n" +
//                "                \"FRecType\": \"0\",\n" +
//                "                \"FPAYAMOUNT_E\": 2.0,\n" +
//                "                \"FPOSTDATE\": \"2024-12-02 00:00:00\",\n" +
//                "                \"FPRICE\": 0.0,\n" +
//                "                \"FMATERIALSEQ\": 0,\n" +
//                "                \"FORDERENTRYID\": 0,\n" +
//                "                \"FRuZhangType\": \"1\",\n" +
//                "                \"FPayType\": \"A\",\n" +
//                "                \"FTaxAmt\": 0.0,\n" +
//                "                \"FNOTVERIFICATEAMOUNT\": 2.0,\n" +
//                "                \"FBankInvoice\": false,\n" +
//                "                \"FNoteStatus\": \"0\",\n" +
//                "                \"FUnique\": 0,\n" +
//                "                \"FMessageInstruct\": \"0\",\n" +
//                "                \"FCollectionAmount\": 0.0,\n" +
//                "                \"FByAgentBank\": false,\n" +
//                "                \"FOverseaPay\": false,\n" +
//                "                \"FXDexchangeRate\": 0.0,\n" +
//                "                \"FRELATEREFUNDAMOUNT\": 0.0,\n" +
//                "                \"F_IsIinvoice\": false\n" +
//                "            }\n" +
//                "        ]\n" +
//                "    }\n" +
//                "}";
        try{
            //业务对象标识
            String formId = "AP_PAYBILL";
            //调用接口
            String resultJson = client.save(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
    //"Id":"100233","ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":"100233","Number":"FKD00000202","DIndex":0}]}}

    @Test
    public void csd(){
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
//        String jsonData = "{\"FormId\":\"SAL_DELIVERYNOTICE\",\"FieldKeys\":\"FID,FBillNo\"," +
//                "\"FilterString\":[{\"FieldName\":\"FOrderNo\",\"Compare\":\"67\",\"Value\":\"XSDD000479\",\"Left\":\"\",\"Right\":\"\",\"Logic\":\"0\"}]," +
//                "\"OrderString\":\"\",\"TopRowCount\":0,\"StartRow\":0,\"Limit\":2000,\"SubSystemId\":\"\"}";
        String jsonData = "{\"FormId\":\"SAL_DELIVERYNOTICE\",\"FieldKeys\":\"FBillNo\"," +
                "\"FilterString\": \"FOrderNo='XSDD000294'\""+
//                "\"FilterString\": \"\"" +
                ",\"OrderString\":\"\",\"TopRowCount\":0,\"StartRow\":0,\"Limit\":2000,\"SubSystemId\":\"\"}";
//        String jsonData = "{\"FormId\":\"SAL_DELIVERYNOTICE\",\"FieldKeys\":\"FID,FBillNo,FSOEntryId,FOrderNo,FOrderSeq\"," +
////                "\"FilterString\": \"FSOEntryId=101370\",\"OrderString\":\"\",\"TopRowCount\":0,\"StartRow\":0,\"Limit\":2000,\"SubSystemId\":\"\"}";
//                "\"FilterString\": \"FOrderNo='XSDD000473'\",\"OrderString\":\"\",\"TopRowCount\":0,\"StartRow\":0,\"Limit\":2000,\"SubSystemId\":\"\"}";
        String resultJson = "";
        try {
            //调用接口
            List<List<Object>> lists = client.executeBillQuery(jsonData);
            String collect = lists.stream().map(innerList -> innerList.stream().map(l -> String.valueOf(l)).collect(Collectors.joining(","))).collect(Collectors.joining(","));
            Map<Object, String> m = new HashMap<>();
            for (List<Object> list : lists) {
                String o = String.valueOf(list.get(0));
                String o1 = String.valueOf(list.get(1));
                if(!m.containsKey(o1)){
                    m.put(o1,o);
                }else {
                    String s = m.get(o1);
                    m.put(o1,s+"_"+o);
                }
            }
            resultJson = String.valueOf(lists);
            System.out.println("接口返回结果: " + resultJson);
            System.out.println("接口返回结果: " + m);

        } catch (Exception e) {
            System.out.println();
        }
    }

    @Test
    public void ddswww(){
        K3CloudApi client = new K3CloudApi();
//请求参数，要求为json字符串
        String jsonData = "{\"FormId\":\"SAL_DELIVERYNOTICE\",\"FieldKeys\":\"FBillNo\"," +
                "\"FilterString\": \"FOrderNo='XSDD000051'\""+
//                "\"FilterString\": \"\"" +
                ",\"OrderString\":\"\",\"TopRowCount\":0,\"StartRow\":0,\"Limit\":2000,\"SubSystemId\":\"\"}";

        try {
            //调用接口
            List<List<Object>> lists = client.executeBillQuery(jsonData);
            String resultJson = lists.stream().map(innerList -> innerList.stream().map(l -> String.valueOf(l)).collect(Collectors.joining(","))).distinct().collect(Collectors.joining(","));
//
//            String resultJson = String.valueOf(client.executeBillQuery(jsonData));
            System.out.println("接口返回结果: " + resultJson);
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    /**
     * 付款单-提交
     * @throws Exception
     */
    @Test
    public void dds(){
        K3CloudApi client = new K3CloudApi();
    //请求参数，要求为json字符串
        String jsonData = "{\"CreateOrgId\":0,\"Numbers\":[],\"Ids\":\"" +
                "100233\",\"SelectedPostId\":0,\"UseOrgId\":0,\"NetworkCtrl\":\"\",\"IgnoreInterationFlag\":\"\"}";
        try{
            //业务对象标识
            String formId = "AP_PAYBILL";
            //调用接口
            String resultJson = client.submit(formId,jsonData);

            //用于记录结果
            Gson gson = new Gson();
            //对返回结果进行解析和校验
            RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
            if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
                System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
            } else {
                fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
            }
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
    /* 本接口用于实现采购订单 (PUR_PurchaseOrder)的保存功能 */
    @Test
    public void atestSavePurchaseOrder() throws Exception {
        String result = api.save("PUR_PurchaseOrder", json);
        Gson gson = new Gson();
        RepoRet sRet = gson.fromJson(result, RepoRet.class);
        if (sRet.isSuccessfully()) {
            chaseorderid = sRet.getResult().getId();
            System.out.printf("采购订单保存接口: %s%n", gson.toJson(sRet.getResult()));
        } else {
            fail("采购订单保存接口: " + gson.toJson(sRet.getResult()));
        }
    }


    /*本接口用于实现采购订单 (PUR_PurchaseOrder)的提交功能*/
    @Test
    public void btestSubmitPurchaseOrder() throws Exception {
        String data = "{\"CreateOrgId\": 0,\"Numbers\": "+"\""+FNumber+"\""+" ,\"Ids\": \"\",\"SelectedPostId\": 0,\"NetworkCtrl\": \"\",\"IgnoreInterationFlag\": \"\"}";
        String result = api.submit("PUR_PurchaseOrder", data);
        Gson gson = new Gson();
        RepoRet repoRet = gson.fromJson(result, RepoRet.class);
        if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
            System.out.printf("采购订单提交接口: %s%n", gson.toJson(repoRet.getResult()));
        } else {
            fail("采购订单提交接口: " + gson.toJson(repoRet.getResult()));
        }

    }

    /*本接口用于实现采购订单 (PUR_PurchaseOrder)的审核功能*/
    @Test
    public void ctestauditPurchaseOrder() throws Exception {
        String data = "{\"CreateOrgId\": 0,\"Numbers\": "+"\""+FNumber+"\""+" ,\"Ids\": \"\",\"SelectedPostId\": 0,\"NetworkCtrl\": \"\",\"IsVerifyProcInst\":\"\",\"IgnoreInterationFlag\": \"\"}";
        String result = api.audit("PUR_PurchaseOrder", data);
        Gson gson = new Gson();
        RepoRet repoRet = gson.fromJson(result, RepoRet.class);
        if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
            System.out.printf("采购订单审核接口: %s%n", gson.toJson(repoRet.getResult()));
        } else {
            fail("采购订单审核接口: " + gson.toJson(repoRet.getResult()));
        }
    }

    /*本接口用于实现采购订单 (PUR_PurchaseOrder)下推采购订单变更单(PUR_POChange)功能*/
    @Test
    public void dtestPurchaseOrderPushPOChange() throws Exception {
        String  paradata = "{\"Ids\": "+"\""+chaseorderid+"\""+",\"Numbers\": [],\"EntryIds\": \"\",\"RuleId\": \"PUR_PurchaseOrder-PUR_POChange\",\"TargetBillTypeId\": \"d588ab5aeb23490aadbb665874b1eabf\",\"TargetOrgId\": 0,\"TargetFormId\": \"PUR_POChange\",\"IsEnableDefaultRule\": false,\"IsDraftWhenSaveFail\": true,\"CustomParams\": {}}";
        String result = api.push("PUR_PurchaseOrder", paradata);
        Gson gson = new Gson();
        RepoRet repoRet = gson.fromJson(result, RepoRet.class);
        if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
            String entity = gson.toJson(repoRet.getResult().getResponseStatus().getSuccessEntitys().get(0));
            POChangeid = new JsonParser().parse(entity).getAsJsonObject().get("Id").toString();
            System.out.printf("采购订单下推采购变更单接口: %s%n", result);
        } else {
            fail("采购订单下推采购变更单接口: " + result );
        }
    }

    /*本接口用于实现采购订单变更单(PUR_POChange)的查看功能*/
    @Test
    public void etestviewPurPochange() throws Exception {
        String data = "{ \"CreateOrgId\": 0, \"Number\": \"\", \"Id\": "+POChangeid+", \"IsSortBySeq\": \"false\"}";
        String result = api.view("PUR_POChange", data);
        Gson gson = new Gson();
        RepoRet repoRet = gson.fromJson(result, RepoRet.class);
        if (repoRet.getResult().getResponseStatus().isIsSuccess()) {

            System.out.printf("采购订单变更单查看接口: %s%n", result);
        } else {
            fail("采购订单变更单查看接口: " + result);
        }
    }


    /*本接口用于实现采购订单变更单(PUR_POChange)的保存功能*/
    @Test
    public void ftestSavePurPochange() throws Exception {
        String data = "{\"NeedUpDateFields\": [\"FBillNo\",\"FChangeReason\"],\"NeedReturnFields\": [\"FBillNo\",\"FChangeReason\"],\"IsDeleteEntry\": \"true\",\"SubSystemId\": \"\",\"IsVerifyBaseDataField\": \"false\",\"IsEntryBatchFill\": \"true\",\"ValidateFlag\": \"true\",\"NumberSearch\": \"true\",\"IsAutoAdjustField\": \"false\",\"InterationFlags\": \"\",\"IgnoreInterationFlag\": \"\",\"IsControlPrecision\": \"false\",\"ValidateRepeatJson\": \"false\",\"Model\": {\"FID\": "+POChangeid+",\"FChangeReason\": \"变更\",\"FEntity\": [{\"FEntryID\": "+POChangeid+" ,\"FDeliEntity\": [{\"FDetailID\": "+POChangeid+"}]}]}}";
        String result = api.save("PUR_POChange", data);
        Gson gson = new Gson();
        RepoRet repoRet = gson.fromJson(result, RepoRet.class);
        if (repoRet.getResult().getResponseStatus().isIsSuccess()) {

            System.out.printf("采购订单变更单保存接口: %s%n", result);
        } else {
            fail("采购订单变更单保存接口: " + result);
        }
    }

    /**
     * 物料获取
     * @throws Exception
     */
    @Test
    public void getMaterials() {
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\"FormId\":\"BD_MATERIAL\",\"FieldKeys\":\"FName,FNumber,FSpecification,FBaseUnitId.FNumber as FUNumber,FUseOrgId.FName as FMatsterName\",\"FilterString\":\"FDocumentStatus='C'\",\"OrderString\":\"\",\"TopRowCount\":0,\"StartRow\":0,\"Limit\":2000,\"SubSystemId\":\"\"}";
        List<Object> resultList = new ArrayList<>();
        try {
            //调用接口
            List<List<Object>> lists = client.executeBillQuery(jsonData);
            String resultJson = String.valueOf(client.executeBillQuery(jsonData));
            System.out.println("接口返回结果: " + resultJson);
            for (List<Object> list : lists) {
                UserModel userModel = new UserModel();
                userModel.setFName((String)list.get(0));
                userModel.setFNumber((String)list.get(1));
                userModel.setSpecification((String)list.get(2));
                userModel.setUnit((String)list.get(3));
                userModel.setUnit((String)list.get(4));
                resultList.add(userModel);
            }
        } catch (Exception e) {

        }
    }


    /**
     * 客户获取
     * @throws Exception
     */
    @Test
    public void getCustomers(){
        K3CloudApi client = new K3CloudApi();
        //请求参数，要求为json字符串
        String jsonData = "{\n" +
                "    \"FormId\": \"BD_Customer\",\n" +
                "    \"FieldKeys\": \"FName,Fnumber\",\n" +
                "    \"FilterString\": \"FDocumentStatus='C'\",\n" +
                "    \"OrderString\": \"\",\n" +
                "    \"TopRowCount\": 0,\n" +
                "    \"StartRow\": 0,\n" +
                "    \"Limit\": 2000,\n" +
                "    \"SubSystemId\": \"\"\n" +
                "}";
        String resultJson = null;
        List<Object> resultList = new ArrayList<>();
        try {
            //调用接口
            List<List<Object>> lists = client.executeBillQuery(jsonData);
            for (List<Object> list : lists) {
                UserModel userModel = new UserModel();
                userModel.setFName((String)list.get(0));
                userModel.setFNumber((String)list.get(1));
                resultList.add(userModel);
            }
            resultJson = String.valueOf(lists);
            System.out.println("接口返回结果: " + resultJson);
        } catch (Exception e) {
            System.out.println("接口返回结果: " + resultJson);
        }
    }
    public void dd222(){
        Map<String, Object> map = new HashMap<>();
        map.put("paymentName__c","海南战区团战政策");
        map.put("employeeCode800__c","00135");
        map.put("ownerId",1233269387297425L);
        map.put("id",3510707784450717L);
        map.put("cVouchID__c","");
        map.put("customItem13__c","收款 (陈琼园)");
        map.put("customItem35__c",1);
        map.put("state__c",2);
        map.put("payment__c",39);
        map.put("lockStatus",2);
        map.put("updatedBy",2625989731353298L);//
        map.put("customItem27__c",1729008000000L);//
        map.put("entityType",1254575355314843L);
        map.put("belongId",1254575339700975L);//
        map.put("customItem17__c",0);//
        map.put("applicantId",1233269387297425L);//
        map.put("deptCode__c","200108");
        map.put("customItem20__c",34800);
        map.put("approvalStatus",3);//
        map.put("operator__c","魏凯强");//
        map.put("settlement__c",2);
        map.put("employeeName__c","魏凯强");//
        map.put("createdAt",1729041401305L);//
        map.put("dimDepart",1510516854227656L);
        map.put("customItem16__c",0);//合计金额-
        map.put("employeeCode700__c","00109");
        map.put("modifyPerson__c","胡秋月");//姓名-
        map.put("name","0000034921");//-
        map.put("updatedAt",1730615905917L);//-
        map.put("customItem33__c",1);
        map.put("kehumingcheng__c",3494511881601700L);
        map.put("createdBy",1233269387297425L);//
        map.put("cusCode__c","0104660");
        map.put("apiKey","customEntity24__c");
        map.put("entryDate__c",1728662400000L);//日期
        map.put("cusDeptId__c","1510516854227656");//客户部门id

        String jsonData = JSONObject.toJSONString(map);
    }

}
